﻿namespace EasyWeb
{
    using System;
    using System.IO;
    using System.Web.Hosting;
    using SystemEnvironment = System.Environment;

    internal static partial class EWHelpers
    {
        public static class Environment
        {
            public static string MapPath(string path)
            {
                EWDebug.IsNotNullOrEmpty(path, "path");

                if (HostingEnvironment.IsHosted)
                {
                    return HostingEnvironment.MapPath(path);
                }

                var rootPath = SystemEnvironment.CurrentDirectory;

                if (StringComparer.CurrentCultureIgnoreCase.Compare("~/bin", path) == 0)
                {
                    return rootPath;
                }

                return Path.Combine(rootPath, path.Substring(2));
            }
        }
    }
}
